package com.bx.implatform.controller;

import com.bx.implatform.result.Result;
import com.bx.implatform.result.ResultUtils;
import com.bx.implatform.service.ICallRecordService;
import com.bx.implatform.session.SessionContext;
import com.bx.implatform.vo.CallRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author: yufeng
 * @date: 2024-02-21
 * @description:
 */
@Api(tags = "通话记录")
@RestController
@RequestMapping("/call-record")
@RequiredArgsConstructor
public class CallRecordController {

    private final ICallRecordService callRecordService;

    @GetMapping("/list")
    @ApiOperation(value = "通话记录列表", notes = "获取通话记录列表")
    public Result<List<CallRecordVo>> listCallRecords(String callStatus) {
        List<CallRecordVo> callRecordVos = callRecordService.queryCallRecord(SessionContext.getSession().getUserId(), callStatus);
        return ResultUtils.success(callRecordVos);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增通话记录", notes = "新增通话记录")
    public Result addCallRecord(@RequestBody CallRecordVo callRecordVo) {
        callRecordService.addCallRecord(callRecordVo);
        return ResultUtils.success();
    }

    @GetMapping("/personal")
    @ApiOperation(value = "与某人通话记录", notes = "获取与某人通话记录")
    public Result<Map<Long, List<CallRecordVo>>> getPersonalCallRecords(Long peerUserId) {
        Map<Long, List<CallRecordVo>> callRecords = callRecordService.queryPersonalCallRecord(SessionContext.getSession().getUserId(), peerUserId);
        return ResultUtils.success(callRecords);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据Id删除通话记录", notes = "根据Id删除通话记录")
    public Result delete(@PathVariable("id") Long id) {
        callRecordService.deleteCallRecord(id);
        return ResultUtils.success();
    }
}
